package yang.VirtualMachine.chapter11.asmTime;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class TimeStatMethodAdater extends MethodVisitor implements Opcodes {

	public TimeStatMethodAdater(MethodVisitor mv) {
		super(Opcodes.ASM5, mv);
	}
	
	@Override
	public void visitCode() {
		// 调用start方法
		visitMethodInsn(Opcodes.INVOKESTATIC, TimeStat.class.getName().replace(".", "/"), "start", "()V");
		super.visitCode();
	}
	
	@Override
	public void visitInsn(int opcode) {
		// 若为返回语句，则调用end方法
		if (opcode >= IRETURN && opcode <= RETURN) {
			visitMethodInsn(Opcodes.INVOKESTATIC, TimeStat.class.getName().replace(".", "/"), "end", "()V");
		}
		mv.visitInsn(opcode);
	}

	

}
